package com.pro.springbootshop.controller;

import com.pro.springbootshop.entity.Buyer;
import com.pro.springbootshop.entity.Seller;
import com.pro.springbootshop.entityExtend.SellerReturn;
import com.pro.springbootshop.service.SellerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class SellerController {
    @Autowired
    SellerService sellerService;
    @ApiOperation("商家登录")
    @PostMapping("/api/seller/login")
    public String loginSeller(@RequestBody Seller seller){
        return sellerService.loginSeller(seller);
    }
    @ApiOperation("获取商家信息")
    @GetMapping("/api/seller/{token}")
    public Seller getSeller(@PathVariable(name = "token") String token){
        return sellerService.getSeller(token);
    }
    @ApiOperation("修改商家信息")
    @PostMapping("/api/seller/detail")
    public String updateSeller(@RequestBody Seller seller){
        return sellerService.updateSeller(seller);
    }
    @ApiOperation("修改商家密码")
    @PostMapping("/api/seller/detail/{oldSellerPw}/{sellerPw}")
    public String updateSellerPw(@PathVariable(name = "oldSellerPw") String oldSellerPw,@PathVariable(name = "sellerPw") String sellerPw, HttpServletRequest request){
        String token = request.getHeader("token");
        return sellerService.updateSellerPw(oldSellerPw,sellerPw,token);
    }
    @ApiOperation("商家注册")
    @PostMapping("/api/seller/register")
    public String insertSeller(@RequestBody Seller seller){ return  sellerService.insertSeller(seller); }
    @ApiOperation("分页获取商家")
    @GetMapping("/api/seller/{page}/{limit}")
    public SellerReturn pageGetSeller(@PathVariable(name = "page") Integer page, @PathVariable(name = "limit") Integer limit){
        return sellerService.pageGetSeller(page,limit);
    }
    @ApiOperation("管理员删除商家")
    @PostMapping("/api/admin/seller/delete/{sellerId}")
    public String adminDeleteSeller(@PathVariable(name = "sellerId") String sellerId){
        return sellerService.adminDeleteSeller(sellerId);
    }
}
